/******************************************************************************
 * Copyright (C) 2016  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODE_SYSTEM_EVENT_WIN32_H_
#define NODE_SYSTEM_EVENT_WIN32_H_

#define WIN32_MEAN_AND_LEAN
#include <Windows.h>
#include <node/noncopyable.h>

namespace node {
    namespace system {

        class event_impl : private noncopyable
        {
        protected:
            event_impl(bool init_state, bool auto_reset);
            ~event_impl(void);

            bool set_impl(void);
            bool reset_impl(void);
            bool wait_impl(void);
            bool wait_impl(long milliseconds);

        private:
            HANDLE _event;
        };

        inline bool event_impl::set_impl(void)
        {
          return (::SetEvent(_event) == TRUE);
        }
        inline bool event_impl::reset_impl(void)
        {
          return (::ResetEvent(_event) == TRUE);
        }
        inline bool event_impl::wait_impl(void)
        {
            return (::WaitForSingleObject(_event, INFINITE) != WAIT_FAILED);
        }
        inline bool event_impl::wait_impl(long milliseconds)
        {
            return (::WaitForSingleObject(_event, (DWORD)milliseconds) != WAIT_FAILED);
        }

}}

#endif //NODE_SYSTEM_EVENT_WIN32_H_
